Simple reccurssion, you have a base case where you have just 1 digit, simply return it, you have recussive case, you add all the digit and return addDigits adds all these digit recurssively
class Solution {
public int addDigits(int num) {
// base case
if(num < 10) return num;
int res = 0;
while(num != 0){
res += num % 10;
num /= 10;
}
return addDigits(res);
}
}
